define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/index' + location.search,
                    add_url: 'order/add',
                    edit_url: 'order/edit',
                    del_url: 'order/del',
                    multi_url: 'order/multi',
                    import_url: 'order/import',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {field: 'id', title: __('Id')},
                        {field: 'order_sn', title: __('Order_sn'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'vehicle_id', title: __('Vehicle_id')},
                        {field: 'vehicle_name', title: __('Vehicle_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        // {field: 'category_ids', title: __('Category_ids'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'user.username', title: __('下单人')},
                        {field: 'detection.username', title: __('检测人')},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4'),"5":__('Status 5'),"6":__('检测中'),"-1":__('已取消')}, formatter: Table.api.formatter.status},
                        {field: 'register_time', title: __('Register_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'mileage', title: __('Mileage')},
                        {field: 'vin', title: __('vin')},
                        {field: 'up_address', title: __('上门地址')},
                        {field: 'up_time', title: __('上门时间')},
                        {field: 'contacts', title: __('联系人')},
                        {field: 'vin_image', title: __('行驶证照片'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'use_type', title: __('Use_type'), searchList: {"1":__('Use_type 1'),"2":__('Use_type 2'),"0":'-'}, formatter: Table.api.formatter.normal},
                        {field: 'car_type', title: __('Car_type'), searchList: {"1":__('Car_type 1'),"2":__('Car_type 2'),"0":'-'}, formatter: Table.api.formatter.normal},
                        {field: 'energy_type', title: __('能源类型'), searchList: {"1":__('新能源'),"2":__('燃油车')}, formatter: Table.api.formatter.normal},
                        {field: 'pay_time', title: __('Paytime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'taking_time', title: __('Taking_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'completion_time', title: __('Completion_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'edit',
                                    icon: 'fa fa-pencil',
                                    title: __('审核'),
                                    extend: 'data-toggle="tooltip" data-area=\'["100%", "100%"]\'',
                                    classname: 'btn btn-xs btn-success btn-editone',
                                    url: $.fn.bootstrapTable.defaults.extend.edit_url
                                }
                            ],
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
